package LeetcodeTest_forty;
//915. 分割数组

import java.util.Arrays;

public class partitionDisjoint
{
    public static void main(String[] args)
    {
        int[] A={1,1,1,0,6,12};
        System.out.println(Solutions.partitionDisjoint(A));
    }
}
class Solutions
{
    public static int partitionDisjoint(int[] A)
    {
        int n=A.length;
        int[] minNum=new int[n-1];
        for(int i=n-2;i>=1;i--)
        {
            if(i==n-2)
                minNum[i]=A[i];
            else
                minNum[i]=Math.min(A[i],minNum[i+1]);
        }
        int maxNum=A[0];
        for(int i=0;i<n-1;i++)
        {
            maxNum=Math.max(A[i],maxNum);
            if(maxNum<=minNum[i+1])
                return i+1;
        }
        return 0;
    }
}